import { ref } from 'vue';
import { checkMobil } from '@/utils/regExp';

export default () => {
    // 字段配置
    const formConfig = ref([
        {
            tag: 'n-input',
            label: '姓名',
            code: 'name',
            value: '',
            nullValue: '',
            visible: true,
            comStyle: {},
            comProps: {
                type: 'text',
                placeholder: '请输入姓名'
            }
        },
        {
            tag: 'form-radio',
            label: '性别',
            code: 'gender',
            value: '',
            nullValue: '',
            visible: true,
            comProps: {
                options: [
                    {
                        value: 'man',
                        label: '男'
                    },
                    {
                        value: 'woman',
                        label: '女'
                    }
                ]
            }
        },
        {
            tag: 'n-date-picker',
            label: '出生日期',
            code: 'birth',
            value: null,
            nullValue: null,
            visible: true,
            comProps: {
                type: 'date',
                placeholder: '请选择日期',
                clearable: true
            }
        },
        {
            tag: 'form-upload',
            label: '头像',
            code: 'headImage',
            value: {},
            nullValue: {},
            comProps: {}
        },
        {
            tag: 'n-input',
            label: '账号',
            code: 'account',
            value: '',
            nullValue: '',
            visible: true,
            comProps: {
                placeholder: '请输入账号'
            }
        },
        {
            tag: 'n-input',
            label: '密码',
            code: 'password',
            value: '',
            nullValue: '',
            visible: true,
            comProps: {
                type: 'password',
                placeholder: '请输入密码',
                showPasswordOn: 'click'
            }
        },
        {
            tag: 'n-input',
            label: '手机号',
            code: 'phoneNumber',
            value: '',
            nullValue: '',
            visible: true,
            comProps: {
                type: 'number',
                placeholder: '请输入手机号'
            }
        },
        {
            tag: 'n-input',
            label: '邮箱',
            code: 'email',
            value: '',
            nullValue: '',
            visible: true,
            comProps: {
                placeholder: '请输入邮箱'
            }
        }
    ]);
    // 校验配置
    const formRules = ref({
        name: [
            {
                required: true,
                message: '用户名称不能为空',
                trigger: 'blur'
            }
        ],
        phoneNumber: [
            {
                required: true,
                validator: (rules, val) => checkMobil(val),
                message: '电话号码格式不正确',
                trigger: 'blur'
            }
        ]
    });
    return {
        formConfig,
        formRules
    };
};
